// pages/lifeCircle/searchCircle/searchCircle.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    first: false,
    judge: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  toPostList:function(e){
    var index = e.currentTarget.dataset.index;
    var that = this;
    wx.navigateTo({
      url: '/pages/lifeCircle/comments?topic_id='+that.data.search_list[index][4],
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  //获取搜索栏内容
  onInputValue: function(e){
    var str = e.detail.value;
    var that = this;
    that.setData({
      str: str
    })
  },

  //搜索帖子  收集formID
  onCircleList: function(e){
    var that = this;
    var str = that.data.str;  
    if(str == ''){
      wx.showToast({
        icon: 'none',
        title: '请输入内容',
      })
    }else{
      wx.request({
        url: app.globalData.targetUrl + 'discuss/topics/search',
        method: 'GET',
        data: {
          'str': str
        },
        success: res => {
          var res_list = res.data.data;
          var first;
          var judge;
          if (res_list.length == 0) {
            that.setData({
              judge: true
            });
          }
          else {
            that.setData({
              judge: false
            });
          }
          for (var i = 0; i < res.data.data.length; i++) {
            res_list[i][0] = res.data.data[i].title;
            res_list[i][1] = res.data.data[i].comment_cnt;
            res_list[i][2] = res.data.data[i].like_cnt;
            res_list[i][3] = res.data.data[i].view_cnt;
            res_list[i][4] = res.data.data[i].id;
          }

          that.setData({
            search_list: res_list,
            first: true
          })
        }
      })
    }
    // 收集formID
    var user_id = wx.getStorageSync('user_id');
    var formId = e.detail.formId;
    app.saveFormId(user_id, formId);
  },
  onTodetail:function(e){
    var thst=this;
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})